package org.su.webadapter.bind;


import org.su.generalmvc.IEditor;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.lang.reflect.Method;

/**
 * 字符串参数到对象的转换；
 * 
 * 
 */
public abstract class AbstractParameterEditor implements IEditor {

	@Override
	public Object getParamValue(String paramName, Class<?> paramType, int paramIndex, Method writer, ServletRequest request,
								ServletResponse response) {
		Object result = null;
		try {
			result = parseText(request.getParameter(paramName));
		} catch (NumberFormatException ex) {
			throw new ParamBindException(ex, paramName);
		}
		return result;
	}


	public abstract Object parseText(String text);
}
